import java.net.*;
import java.io.*;

/*
	bai toan: gui thong diep tu server cho client, in thong diep do ra man hinh
*/

public class Server
{
	public static void main(String args[]){
		
		//khai bao bien 
		ServerSocket mySocket= null;
		String data = "Hi, there!";
		
		//Khoi tao socket
		try{
			mySocket = new ServerSocket(1234); //khoi tao socket lang nghe o cong 1234
			System.out.println("Server's listening"); //thong bao server dang lang nghe
		}catch(IOException e){
			System.err.println("Ko the mo duoc cong 1234");
			System.exit(1);
		}

		Socket myClient; // thuc ra la bien nay ko can thiet
		while(true){
			try{
				myClient = mySocket.accept();

				//send
				PrintWriter out = new PrintWriter(myClient.getOutputStream(), true);
				out.println(data);

				out.close();// dong luong chuyen du lieu

			} catch(IOException e){
				System.err.println("accept failed.");
				System.exit(1);
			}
		}

	}
}